$(document).ready(function() {
	$("#registerMemberForm").validate({
		onkeyup: false,
		onfocusout: false,
		rules: {
			stuNum: {
				required: true,
				digits: true,
				maxlength: 9
			},
			stuName: {
				required: true,
				maxlength: 5
			},
			pass: {
				required: true,
				smallEngAndDigits: true,
				rangelength: [6, 20]
			},
			confirmPass: {
				equalTo: "#pass"
			}
		},
		messages: {
			stuNum: {
				required: "<br />*請輸入學號",
				digits: "<br />*學號只能是數字",
				maxlength: "<br />*學號最多9位"
			},
			stuName: {
				required: "<br />*請輸入姓名",
				maxlength: "<br />*姓名最大長度是5個字"
			},
			pass: {
				required: "<br />*請輸入密碼",
				smallEngAndDigits: "<br />*密碼只能是小寫英文和數字",
				rangelength: "<br />*密碼長度必須在6~20個字之間"
			},
			confirmPass: {
				equalTo: "<br />*必須和密碼一致"
			}
		},
		errorPlacement: function(error, element) {
			error.css("color", "red");
			error.css("font-weight", "bold");
			error.insertAfter(element);
		},
		submitHandler: function(form) {
			$("#registerSubmit").attr("disabled", "true");
			$(form).ajaxSubmit({
				success: function(resp) {
					if (resp == "1") {
						var stuNum = $("#stuNumText").val();
						var stuName = $("#stuNameText").val();
						
						$(location).attr("href", "./addMemberSuc?stuNum=" + stuNum + "&stuName=" + stuName);
					}
					else {
						alert("此學號已經被註冊過");
						$("#registerSubmit").removeAttr("disabled");
					}
				}
			});
		}
	});
});